package com.recommend.recommendkeyword.controller;

import com.recommend.recommendkeyword.common.CommonResponse;
import com.recommend.recommendkeyword.service.KeywordService;
import com.recommend.recommendkeyword.vo.CommentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/keyword")
public class KeywordController {
    @Autowired
    KeywordService keywordService;
    @PutMapping("/isLike")
    public CommonResponse<Object> isLike(@RequestParam String recommendName, @RequestParam String seedKeyword,
                                         @RequestParam int isLike, @RequestParam int userId){
        int rows = keywordService.isLike(recommendName, seedKeyword, isLike, userId);
        if(rows == 0){
            return CommonResponse.createForError("点赞/点踩失败");
        }
        return CommonResponse.createForSuccess("点赞/点踩成功", null);
    }

    @PutMapping("/comment")
    public CommonResponse<Object> comment(@RequestParam String recommendName, @RequestParam String seedKeyword,
                                          @RequestParam String comment, @RequestParam int userId){
        int rows = keywordService.comment(recommendName, seedKeyword, comment, userId);
        if(rows == 0){
            return CommonResponse.createForError("评论失败");
        }
        return CommonResponse.createForSuccess("评论成功", null);
    }

    @GetMapping("/comment")
    public CommonResponse<List<CommentVO>> getComment(@RequestParam int recommendId){
        List<CommentVO> commentVOList = keywordService.getComment(recommendId);
        if(commentVOList == null || commentVOList.isEmpty()){
            return CommonResponse.createForError("查看评论失败");
        }
        return CommonResponse.createForSuccess("查看评论成功", commentVOList);
    }
}
